package com.budayi.controller;

import com.budayi.commom.annotation.JsonParam;
import com.budayi.common.exception.BlException;
import com.budayi.common.exception.ExceptionEnum;
import com.budayi.common.group.TestOne;
import com.budayi.common.group.TestTwo;
import com.budayi.service.TestService;
import com.budayi.vo.JsonResult;
import com.budayi.vo.TestVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * @author LIBOFEI
 * @ClassName TestController
 * @description
 * @date 2021/5/17 15:47
 * @Version 1.0
 **/
@RestController
@RequestMapping("/test")
public class TestController {



    @RequestMapping("/add")
    public JsonResult addUser(@JsonParam("userId")String userId,
                              @JsonParam("status")Long status,
                              @JsonParam("price") BigDecimal price,
                              @JsonParam("name")String name){

         Map<String,Object> result = new HashMap<>();
         result.put("userId",userId);
         result.put("status",status);
         result.put("name",name);
         result.put("price",price);
        return JsonResult.success(result);
     }


    @RequestMapping("/addVo")
    public JsonResult addVo(@RequestBody  TestVo vo){
        if( 1 == 1){
            throw new BlException(ExceptionEnum.BRAND_NOT_FOUND);
        }
        return JsonResult.success(vo);
    }

    @Autowired
    private TestService testService;

    @RequestMapping("/testAsync")
    public JsonResult testAsync(){
        testService.test();
        return JsonResult.success();
    }

}
